<?php
	require_once("../../../include/connect.php");
	require_once("../../../include/datetime.php");
	$type = end(explode(".",$_FILES["file"]["name"]));
	$name = $_POST['name'];
	$date = day_now();
	if($name != "")
	{
		if( $type == "pdf" )
		{
			if ($_FILES["file"]["error"] > 0)
				header("Location:../index.php?p=lst_ans&msg=err&info=".$_FILES["file"]["error"]."");
			else
				if (file_exists("../../../img/upload/answer/".$_FILES["file"]["name"]))
				  header("Location:../index.php?p=lst_ans&msg=exist&info=".$_FILES["file"]["name"]."");
				else
					{
                                                move_uploaded_file($_FILES["file"]["tmp_name"], "../../../img/upload/answer/".$_FILES["file"]["name"]);							
						$query = mysql_query(" INSERT INTO answer(name,content,date) VALUES(N'$name', '".$_FILES["file"]["name"]."', '$date') ");
						if($query)
						{
							move_uploaded_file($_FILES["file"]["tmp_name"], "../../../img/upload/answer/".$_FILES["file"]["name"]);
							header("Location:../index.php?p=lst_ans&msg=success&info=successful");	
						}
					}
		}
		else
			header("Location:../index.php?p=lst_ans&msg=err_type");	
	}
	else
		header("Location:../index.php?p=lst_ans&msg=err&info=Vui lòng nhập tên đề thi");	
?>